package com.hhs.storage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hhs.storage.bean.InputParam;
import com.hhs.storage.bean.ResponseInfo;
import com.hhs.storage.bean.XmClazz;
import com.hhs.storage.bean.XmUserClazz;
import com.hhs.storage.dao.XmClazzDao;
import com.hhs.storage.service.XmClazzService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hhs.storage.service.XmUserClazzService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author chx
 * @since 2024-10-19
 */
@Service
public class XmClazzServiceImpl extends ServiceImpl<XmClazzDao, XmClazz> implements XmClazzService {
    @Resource
    private XmUserClazzService xmUserClazzService;
    @Override
    public Map<String, Object> addStu(InputParam inputParam) {
        String clazzId=inputParam.getId();
        String[] stuIds=inputParam.getIds().split(",");
        QueryWrapper<XmUserClazz> qw=new QueryWrapper<XmUserClazz>();
        qw.in("user_id",stuIds);
        qw.eq("clazz_id",clazzId);
        xmUserClazzService.remove(qw);
        for(String stuId:stuIds){
            XmUserClazz xmUserClazz=new XmUserClazz();
            xmUserClazz.setClazzId(clazzId);
            xmUserClazz.setUserId(stuId);
            xmUserClazzService.save(xmUserClazz);
        }
        return ResponseInfo.success();
    }

    @Override
    public Map<String, Object> cancelStu(InputParam inputParam) {
        String clazzId=inputParam.getId();
        String[] stuIds=inputParam.getIds().split(",");
        QueryWrapper<XmUserClazz> qw=new QueryWrapper<XmUserClazz>();
        qw.in("user_id",stuIds);
        qw.eq("clazz_id",clazzId);
        xmUserClazzService.remove(qw);
        return ResponseInfo.success();
    }
}
